using System;
using System.Collections.Generic;
using System.Text;
using AopAlliance.Intercept;

namespace Sedna.Core.Event.Parsers
{
    public class DefaultSourceParser: IEventSourceParser
    {
        public object GetEventSource(IMethodInvocation methodInvocation, EventfulAttribute eventfulAttribute, Object invocationResult)
        {
            if (EventSource.MethodReturn == eventfulAttribute.EventSource)
            {
                return invocationResult;
            }
            else if (EventSource.MethodParameter == eventfulAttribute.EventSource
                     && methodInvocation.Arguments != null
                     && methodInvocation.Arguments.Length > 0)
            {
                return methodInvocation.Arguments[0];
            }

            return null;
        }
    }
}
